﻿using Architecture.Api.Application.Commands.SourceCommand;
using Architecture.Domain.Services.Interface;
using Architecture.Domian.Common;
using Architecture.Domian.DTO;
using Architecture.Domian.Entity;
using MediatR;

namespace Architecture.Api.Application.CommandHandlers.SourceHandler
{
    public class SourceReadCommandHandler : IRequestHandler<SourceReadCommand, List<GoodsInfo>>
    {
        private readonly ISourceService _sourceService;

        public SourceReadCommandHandler(ISourceService sourceService)
        {
            _sourceService = sourceService;
        }

        public async Task<List<GoodsInfo>> Handle(SourceReadCommand request, CancellationToken cancellationToken)
        {
            return await _sourceService.GetGoodsInfoAsync();
        }
    }

    public class SourceReadPageCommandHandler : IRequestHandler<SourceReadPageCommand, PageResult<SourceInfoDTO>>
    {
        private readonly ISourceService _sourceService;
        public SourceReadPageCommandHandler(ISourceService sourceService)
        {
            _sourceService = sourceService;
        }

        public async Task<PageResult<SourceInfoDTO>> Handle(SourceReadPageCommand request, CancellationToken cancellationToken)
        {
            return await _sourceService.GetSourceInfoPage(request.GoodNo,request.Batch,request.Deadline,request.size, request.index);
        }
    }

    public class SourceReadByIdCommandHandler : IRequestHandler<SourceReadByIdCommand, SourceInfoDTO>
    {
        private readonly ISourceService _sourceService;
        public SourceReadByIdCommandHandler(ISourceService sourceService)
        {
            _sourceService = sourceService;
        }
        public async Task<SourceInfoDTO> Handle(SourceReadByIdCommand request, CancellationToken cancellationToken)
        {
            return await _sourceService.GetSourceInfoBySourceId(request.SourceId);
        }
    }
}
